package junit;

import static org.junit.Assert.*;

import org.junit.Test;

import error_checking.ErrorChecker;
import error_checking.PurchaseInputChecker;

/**
 * 
 * @author Naomi Robert
 * 
 * Tests if PurchaseInputChecker works correctly and identifies
 *  any errors with user input for quantities in the store
 *
 */

public class PurchaseInputTest {

	private ErrorChecker check;
	private String[] purchases = new String[6];
	
	@Test
	public void testNullInput(){
		for(int i=0; i<purchases.length; i++)
			purchases[i] = null;
		
		check = new PurchaseInputChecker(purchases);
		
		assertEquals(check.getErrorText(), "");
		assertFalse(check.hasError());
	}
	
	@Test
	public void testInvalidCharacters(){
		for(int i=0; i<purchases.length; i++)
			purchases[i] = "0";
		purchases[2] = "abc%^&";
		
		check = new PurchaseInputChecker(purchases);
		
		assertEquals(check.getErrorText(), "Invalid quantity of clothing!");
		assertTrue(check.hasError());
	}
	
	@Test
	public void testNegativeInput(){
		for(int i=0; i<purchases.length; i++)
			purchases[i] = "0";
		purchases[4] = "-3";
		
		check = new PurchaseInputChecker(purchases);
		
		assertEquals(check.getErrorText(), "Invalid number of wagon wheels!");
		assertTrue(check.hasError());
	}

	@Test
	public void testLargeNum(){
		for(int i=0; i<purchases.length; i++)
			purchases[i] = "0";
		purchases[0] = "1"+Integer.MAX_VALUE;
		
		check = new PurchaseInputChecker(purchases);
		
		assertEquals(check.getErrorText(), "Invalid number of oxen!");
		assertTrue(check.hasError());
	}
	

	@Test
	public void testValidNum(){
		for(int i=0; i<purchases.length; i++)
			purchases[i] = ""+i;
		
		check = new PurchaseInputChecker(purchases);
		
		assertEquals(check.getErrorText(), "");
		assertFalse(check.hasError());
	}
}

